﻿/*
 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
 */

#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QFrame>
#include <QImage>
#include <QApplication>
#include <QFile>
#include "BurnToolVersion.h"
#include "AboutWindow.h"

namespace BurnDlg {

namespace {
    const int MAXWIDTH = 480;
    const int MAXHEIGHT = 240;
    const int FRAME_WIDTH = 460;
    const int FRAME_HEIGHT = 1;
    const int OKBTN_WIDTH = 80;
    const int OKBTN_HEIGHT = 25;
    const int STRETCH_TYPE_ONE = 30;
    const int STRETCH_TYPE_TWO = 15;
    const int STRETCH_TYPE_THREE = 20;
    const int PIXELSIZE = 15;
    const int ABOUT_FONT_WEIGHT = 70;
}

AboutWindow::AboutWindow(QWidget *parent) : QWidget(parent)
{
    InitUi();
}

void AboutWindow::InitUiLayout1(QVBoxLayout &pLayout)
{
    QLabel *imageLabel = new QLabel(this);
    pLayout.addWidget(imageLabel, 0, Qt::AlignCenter);
    pLayout.addStretch(STRETCH_TYPE_ONE);
    QLabel *titleLabel =  new QLabel(this);
    pLayout.addWidget(titleLabel);
    titleLabel->setText("BurnTool");
    QFont ft;
    ft.setWeight(ABOUT_FONT_WEIGHT);
    titleLabel->setFont(ft);
    pLayout.addWidget(titleLabel, 0, Qt::AlignCenter);
    pLayout.addStretch(STRETCH_TYPE_ONE);

    QLabel *label1 = new QLabel(this);
    label1->setWordWrap(true);
    label1->setText(QString(tr("Product: ") + BurnDlg::VERSION + tr(", Built: ") + BurnDlg::BUILD_TIME));

    pLayout.addWidget(label1);
    pLayout.addStretch(STRETCH_TYPE_TWO);

    QFrame *frame = new QFrame();
    frame->setFixedSize(FRAME_WIDTH, FRAME_HEIGHT);
    frame->setStyleSheet("background-color:grey");
    pLayout.addWidget(frame, 0, Qt::AlignCenter);
    pLayout.addStretch(STRETCH_TYPE_TWO);

    QHBoxLayout *hLayout1 = new QHBoxLayout();
    pLayout.addLayout(hLayout1);
    QLabel *label2 = new QLabel();
    hLayout1->addWidget(label2, 0, Qt::AlignLeft);

    pLayout.addStretch(STRETCH_TYPE_THREE);
}

void AboutWindow::InitUi()
{
    setWindowTitle(tr("About BurnTool"));
    setFixedSize(MAXWIDTH, MAXHEIGHT);
    setWindowFlags(Qt::WindowCloseButtonHint | Qt::Dialog);
    setWindowModality(Qt::ApplicationModal);
    setAutoFillBackground(true);
    QVBoxLayout *layout = new QVBoxLayout();
    if (layout == nullptr) {
        return;
    }
    setLayout(layout);
    InitUiLayout1(*layout);

    QHBoxLayout *hLayout2 = new QHBoxLayout();
    layout->addLayout(hLayout2);
    hLayout2->addStretch();
    QLabel *label3 = new QLabel(this);
    hLayout2->addWidget(label3);
    QLabel *linkLabel = new QLabel(this);
    linkLabel->setOpenExternalLinks(true);
    QFont linkFt;
    linkFt.setPixelSize(PIXELSIZE);
    linkLabel->setFont(linkFt);
    hLayout2->addWidget(linkLabel);
    hLayout2->addStretch();

    QPushButton *okBtn = new QPushButton();
    okBtn->setText(tr("OK"));
    okBtn->setFixedSize(OKBTN_WIDTH, OKBTN_HEIGHT);
    layout->addWidget(okBtn, 0, Qt::AlignRight);
    connect(okBtn, SIGNAL(clicked()), this, SLOT(close()));
}

}
